package day3;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author oldliu
 * @since 1.0
 */
public class School implements Comparable<School>, Serializable {
    private String name = "北大青鸟加盟中心";
    private String addr;
    //机房和教室数目
    private int rooms;
    private int labs;
    //方法，显示学校的信息


    public School() {
    }

    public School(String name, String addr, int rooms, int labs) {
        this.name = name;
        this.addr = addr;
        this.rooms = rooms;
        this.labs = labs;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public int getRooms() {
        return rooms;
    }

    public void setRooms(int rooms) {
        this.rooms = rooms;
    }

    public int getLabs() {
        return labs;
    }

    public void setLabs(int labs) {
        this.labs = labs;
    }

//    //对象散列码
//    @Override
//    public int hashCode() {
//        return this.name==null?0:this.name.hashCode();
//    }
//    //待比较的对象上，重写equals
//    //把学校对象的比较，比较名字。。。
//    @Override
//    public boolean equals(Object obj) {
//        if(this==obj)
//            return true;
//
//        if (obj instanceof School) {
//            School s = (School) obj;
//            if (this.name == null) {
//                if (s.name == null)
//                    return true;
//                return false;
//            }
//            return this.name.equals(s.name);
//        }
//        return false;
//    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        School school = (School) o;
        return Objects.equals(name, school.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    @Override
    public String toString() {
        return "School{" +
                "name='" + name + '\'' +
                ", addr='" + addr + '\'' +
                ", rooms=" + rooms +
                ", labs=" + labs +
                '}';
    }
    //返回0，this和o相等
    //>0,this>o
    //<0: this<o
    @Override //用教室和机房的数目作为比较的条件
    public int compareTo(School o) {
        //this.name.compareTo(o.name);

        return (this.labs+this.rooms)-(o.labs+o.rooms);
    }
}
